#include "PhysicsObject.h"

PhysicsObject::PhysicsObject(Ogre::SceneManager* SceneMgr,Ogre::Entity* ent,btRigidBody* body,float scale,btDynamicsWorld* world):
					entity(ent),body(body),mSceneMgr(SceneMgr),scale(scale),world(world)
{
	node = mSceneMgr->getRootSceneNode()->createChildSceneNode();
	node->attachObject(entity);

	node->scale(scale,scale,scale);

	btVector3 pos = body->getCenterOfMassPosition();
	node->setPosition(pos.getX(),pos.getY(),pos.getZ());

	btQuaternion orientation = body->getOrientation();
	Ogre::Quaternion quat(orientation.getW(),orientation.getX(),orientation.getY(),orientation.getZ());
	node->setOrientation(quat);

}
PhysicsObject::~PhysicsObject()
{
	node->detachAllObjects();
	world->removeRigidBody(body);
	delete body;
	delete entity;


}

void PhysicsObject::update()
{
	btVector3 pos = body->getCenterOfMassPosition();
	node->setPosition(pos.getX(),pos.getY(),pos.getZ());

	btQuaternion orientation = body->getOrientation();
	Ogre::Quaternion quat(orientation.getW(),orientation.getX(),orientation.getY(),orientation.getZ());
	node->setOrientation(quat);
}
